package com.whfc.wxmp.api.emp.service.impl;

import com.whfc.common.file.FileHandler;
import com.whfc.common.file.FilePathConfig;
import com.whfc.common.util.RandomUtil;
import com.whfc.emp.param.AppEmpInputDataAddParam;
import com.whfc.emp.service.AppEmpInputDataService;
import com.whfc.entity.dto.OssPathDTO;
import com.whfc.wxmp.api.emp.service.MpEmpInputDataService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

@Service
public class MpEmpInputDataServiceImpl implements MpEmpInputDataService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @DubboReference(interfaceClass = AppEmpInputDataService.class, version = "1.0.0")
    private AppEmpInputDataService appEmpInputDataService;

    @Autowired
    private FilePathConfig filePathConfig;

    @Autowired
    private FileHandler fileHandler;

    @Override
    public void add(AppEmpInputDataAddParam param) {
        appEmpInputDataService.add(param);
    }

    @Override
    public OssPathDTO upload(MultipartFile file) {
        String upload = "";
        try {
            String path = filePathConfig.getFilePath("emp/faceGateRecord", RandomUtil.getRandomFileName(), "png");
            InputStream inputStream = file.getInputStream();
            upload = fileHandler.upload(path, inputStream);
        } catch (Exception e) {
            logger.error("上传打卡照片失败", e);
        }
        return new OssPathDTO(upload);
    }
}
